package com.hgxd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.entity.vo.RobotDispatchingManagementPoVo;
import com.hgxd.result.Result;
import io.netty.util.internal.StringUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;


import com.hgxd.service.IRobotDispatchingManagementService;
import com.hgxd.entity.RobotDispatchingManagement;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 调度管理 前端控制器
 * </p>
 *
 * @author wtf
 * @since 2023-12-01
 */
@Api(tags = "机器人调度管理")
@RestController
@RequestMapping("/api/robot-dispatching-management")
public class RobotDispatchingManagementController {
    @Resource(name = "RobotDispatchingManagementServiceImpl")
    private IRobotDispatchingManagementService robotDispatchingManagementService;


    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "无需传入id")
    @ApiImplicitParam(name = "robotDispatchingManagement", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人调度管理-新增",operType = "新增",operContent = "新增")
    public Result<Boolean> insert(@RequestBody RobotDispatchingManagement robotDispatchingManagement) {
        return Result.ok(robotDispatchingManagementService.save(robotDispatchingManagement));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "必须传入id")
    @ApiImplicitParam(name = "robotDispatchingManagement", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人调度管理-修改",operType = "修改",operContent = "修改")
    public Result<Boolean> update(@RequestBody RobotDispatchingManagement robotDispatchingManagement) {
        return Result.ok(robotDispatchingManagementService.updateById(robotDispatchingManagement));
    }

    /**
     * 根据id删除
     */
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除", notes = "必须传入id")
    @ApiImplicitParam(name = "id", value = "id")
    @OperationLogAnnotation(operModule = "机器人调度管理-根据id删除",operType = "删除",operContent = "根据id删除")
    public Result<Boolean> delete(@PathVariable Integer id) {
        return Result.ok(robotDispatchingManagementService.removeById(id));
    }

    /**
     * 批量删除
     */
    @PostMapping("/del/batch")
    @ApiOperation(value = "批量删除", notes = "传入ids")
    @ApiImplicitParam(name = "ids", value = "id的数组")
    @OperationLogAnnotation(operModule = "机器人调度管理-批量删除",operType = "删除",operContent = "批量删除")
    public Result<Boolean> deleteBatch(@RequestBody List<Integer> ids) {
        return Result.ok(robotDispatchingManagementService.removeByIds(ids));
    }

    /**
     * 查询全部
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "查询全部", notes = "无需传参")
    @OperationLogAnnotation(operModule = "机器人调度管理-查询全部",operType = "查询",operContent = "查询全部")
    public Result<List<RobotDispatchingManagement>> findAll() {
        return Result.ok(robotDispatchingManagementService.list());
    }

    /**
     * 根据id查询一个
     */
    @GetMapping("getById/{id}")
    @ApiOperation(value = "根据id查询一个", notes = "传入id")
    @ApiImplicitParam(name = "id", value = "id")
    @OperationLogAnnotation(operModule = "机器人调度管理-根据id查询一个",operType = "查询",operContent = "根据id查询一个")
    public Result<RobotDispatchingManagement> findOne(@PathVariable Integer id) {
        return Result.ok(robotDispatchingManagementService.getById(id));
    }

    /**
     * 分页模糊查询
     */
    @PostMapping("/get/page")
    @ApiOperation(value = "分页模糊查询", notes = "传入对应所需参数")
    @ApiImplicitParam(name = "robotDispatchingManagementPoVo", value = "分页类")
    @OperationLogAnnotation(operModule = "机器人调度管理-分页模糊查询",operType = "查询",operContent = "分页模糊查询")
    public Result<Page<RobotDispatchingManagement>> findPage(@RequestBody RobotDispatchingManagementPoVo robotDispatchingManagementPoVo) {
        LambdaQueryWrapper<RobotDispatchingManagement> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.between(robotDispatchingManagementPoVo.getStartTime()!=null
                &&robotDispatchingManagementPoVo.getEndTime()!=null,
                RobotDispatchingManagement::getStartTime,
                robotDispatchingManagementPoVo.getStartTime(),
                robotDispatchingManagementPoVo.getEndTime()).
                eq(!StringUtil.isNullOrEmpty(robotDispatchingManagementPoVo.getName()),
                        RobotDispatchingManagement::getName,robotDispatchingManagementPoVo.getName())
                .eq(!StringUtil.isNullOrEmpty(robotDispatchingManagementPoVo.getType()),
                        RobotDispatchingManagement::getType,
                        robotDispatchingManagementPoVo.getType());
        return Result.ok(robotDispatchingManagementService.page(new Page<>(robotDispatchingManagementPoVo.getPageNum(), robotDispatchingManagementPoVo.getPageSize()), lambdaQueryWrapper));
    }
}

